<template>
  <div class="backgroundImage">
    <el-image
      style="width: 100%; height: 200px"
      src="https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg"
      fit="cover"
    />
  </div>

  <!-- 用户基本信息 -->
  <div class="userInfo">
    <div class="avatar">
      <el-image
        style="height: 120px; width: 100px"
        src="https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg"
        fit="cover"
      />
    </div>

    <div class="info">
      <div class="signature">{{ signature }}</div>

      <div class="infoItem">
        <div class="label">
          <i class="icon-user-2-fill" style="font-size: 24px"></i>
        </div>
        <div class="value">{{ account }}</div>
      </div>

      <div class="infoItem">
        <div class="label">
          <i class="icon-user-3-line" style="font-size: 24px"></i>
        </div>
        <div class="value">{{ nickname }}</div>
      </div>

      <div class="infoItem">
        <div class="label">
          <i class="icon-phone-fill" style="font-size: 24px"></i>
        </div>
        <div class="value">{{ phone }}</div>
      </div>

      <div class="infoItem">
        <div class="label">
          <i class="icon-mail-fill" style="font-size: 24px"></i>
        </div>
        <div class="value">{{ email }}</div>
      </div>

      <div class="infoItem">
        <div class="label">
          <i class="icon-seedling-fill" style="font-size: 24px"></i>
        </div>
        <div class="value">{{ createTime }}</div>
      </div>

      <div class="infoItem">
        <div class="label">
          <i class="icon-logout-box-r-fill" style="font-size: 24px"></i>
        </div>
        <div class="value">
          <el-button type="danger" size="small" @click="logout">退出</el-button>
        </div>
      </div>
    </div>
  </div>

  <div style="height: 100px"></div>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router'
import 'element-plus/theme-chalk/el-message.css'
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/features/store/store'
import { logoutApi } from '@/request/api/remoteInteraction'

const router = useRouter()

// @ts-ignore
const { nickname, avatar, email, phone, signature, account, createTime } =
  storeToRefs(useUserStore())

// 退出登录
const logout = async () => {
  await logoutApi()
  useUserStore().setLoginStatus()
  window.localStorage.removeItem('token')
  router.push('/loginRedirect')
}
</script>

<style lang="less" scoped>
.backgroundImage {
  width: 100%;
  height: 200px;
}

.userInfo {
  width: 84%;
  margin-left: 8%;
  margin-right: 8%;
  display: flex;
  position: relative;
  border-bottom: 1px solid #dedfe0;

  > .avatar {
    position: relative;
    box-shadow: 0 0 8px 1px #cfcfcf;
    height: 120px;
    width: 100px;
    margin-right: 20px;
    top: -60px;
  }

  > .info {
    position: relative;
    width: calc(100% - 120px);
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;

    > .signature {
      position: absolute;
      top: -46px;
      font-weight: bold;
      color: #fafafa;
      width: 100%;
      height: 42px;
      display: flex;
      align-items: center;
      flex-wrap: wrap;
    }

    > .infoItem {
      padding: 10px;
      display: flex;
      align-items: center;

      > .label {
        font-size: 16px;
        font-weight: bold;
        color: #606266;
        padding-right: 10px;
        width: 32px;
      }

      > .value {
        font-size: 16px;
        font-weight: bold;
        color: #909399;
        display: flex;
        align-items: center;
      }
    }
  }
}
</style>
